package com.cx.mall.demo.handler;

import org.springframework.cloud.stream.binder.PartitionKeyExtractorStrategy;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

@Configuration
public class OrderPartitionKeyExtractor implements PartitionKeyExtractorStrategy {
    @Override
    public Object extractKey(Message<?> message) {
        // 获取消息头中的ORDERLY_KEY
//        return String.valueOf(((Integer) message.getHeaders().get("ORDERLY_KEY")) % 3);
        return message.getHeaders().get("ORDERLY_KEY").toString();
    }
}
